package com.edu.exam.enums.common;

import com.edu.exam.enums.core.BaseEnum;

/**
 * 质量等级枚举
 *
 * 统一的质量等级管理，用于各种需要质量评估的场景
 * 替代分散在各个实体中的重复质量等级定义
 *
 * @author System
 * @version 1.0.0
 * @since 2025-11-13
 */
public enum QualityLevel implements BaseEnum {

    /**
     * 优秀
     */
    EXCELLENT("EXCELLENT", "优秀"),

    /**
     * 良好
     */
    GOOD("GOOD", "良好"),

    /**
     * 满意
     */
    SATISFACTORY("SATISFACTORY", "满意"),

    /**
     * 合格
     */
    ACCEPTABLE("ACCEPTABLE", "合格"),

    /**
     * 需改进
     */
    NEEDS_IMPROVEMENT("NEEDS_IMPROVEMENT", "需改进"),

    /**
     * 较差
     */
    POOR("POOR", "较差"),

    /**
     * 不合格
     */
    UNACCEPTABLE("UNACCEPTABLE", "不合格");

    private final String code;
    private final String description;

    QualityLevel(String code, String description) {
        this.code = code;
        this.description = description;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDescription() {
        return description;
    }
    /**
     * 根据编码查找枚举值
     *
     * @param code 业务编码
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果编码无效
     */
    public static QualityLevel fromCode(String code) {
        if (code == null || code.trim().isEmpty()) {
            throw new IllegalArgumentException("QualityLevel code cannot be null or empty");
        }
        for (QualityLevel level : values()) {
            if (level.getCode().equals(code)) {
                return level;
            }
        }
        throw new IllegalArgumentException("Unknown QualityLevel code: " + code);
    }

    /**
     * 根据描述查找枚举值
     *
     * @param description 显示描述
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果描述无效
     */
    public static QualityLevel fromDescription(String description) {
        if (description == null || description.trim().isEmpty()) {
            throw new IllegalArgumentException("QualityLevel description cannot be null or empty");
        }
        for (QualityLevel level : values()) {
            if (level.getDescription().equals(description)) {
                return level;
            }
        }
        throw new IllegalArgumentException("Unknown QualityLevel description: " + description);
    }

    @Override
    public String toString() {
        return this.code + "(" + this.description + ")";
    }
}